package com.example.mybatisplusdemo1.controller;

import com.example.mybatisplusdemo1.model.User;
import com.example.mybatisplusdemo1.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@RequestMapping(value = "/user")
public class UserController {
    @Autowired
    private IUserService userService;

    @GetMapping(value = "/saveBatch",produces = MediaType.APPLICATION_JSON_VALUE)
    public ResponseEntity<Void> saveBatch(){
        List<User> users = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            User user = new User();
            user.setName("test" + i);
            user.setPassword("123456");
            users.add(user);
        }
        userService.saveBatch(users);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
